var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    balance:{},
    hiddenmodalput: true,//可以通过hidden是否掩藏弹出框的属性，来指定那个弹出框
    cashValue:'',
    onnShow:true,
    onnShow2:true,
    confirm:false,
    cashMoney:''
  },
  //点击按钮痰喘指定的hiddenmodalput弹出框  
  modalinput: function () {
    var that=this;
    if(this.data.balance.ua_account>0){
        this.setData({
            hiddenmodalput: !this.data.hiddenmodalput
        });
    }
    else{
        that.onnShow();
    }
  },
  inputchange:function(e){
    this.setData({
      cashValue:e.detail.value
    })
  },
  //余额不足
  onnShow: function () {
      wx.showModal({
          title: '余额不足，无法提现',
          showCancel:false,
          success:function(res){
              wx.switchTab({
                  url: 'purse'
              })
          }
      })
  },
    //输入金额大于余额
    onnShow2: function () {
        wx.showModal({
            title: '请输入正确金额',
            showCancel:false,
            success:function(res){
                wx.switchTab({
                    url: 'purse'
                })
            }
        })
    },
  //取消按钮  
  cancel: function () {
    this.setData({
      hiddenmodalput: true,
    });
  },  
  //提交  
  confirm: function () {
    var that=this;
    var money2=that.data.cashValue;
      if(that.data.balance.ua_account<money2){
        that.onnShow2();
      }else {
          this.setData({
              hiddenmodalput: true
          });
          util.request(api.RequireCashUrl, { money: money2, unionid: app.globalData.unionid }, 'POST').then(function(res){
            console.log(res)
            that.setData({
              balance: res.data.data
            })
          })

      }
      
  },
  // 钱包数据
  BalancePurse:function(){
    var that = this;
    util.request(api.SelfPurseUrl, { unionid: app.globalData.unionid }).then(function(res){

      if(res.data.code == 200){
        that.setData({
          balance: res.data.data
        })
      }

    })

  },

  //明细
  cashDetail:function(){
    wx:wx.navigateTo({
      url: '../detailed/detailed'
    })
  },
  complate:function(){
    wx.navigateBack({
      delta:1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.BalancePurse()
  }

})